import java.time.LocalDate;
import java.time.LocalTime;

public class FormatChecker {

    public static boolean formatCheckDateString(String str) {
        // 2017-08-01
        String[] dateParts = str.split("-");
        if (dateParts.length != 3)
            return false;

        try {
            int year = Integer.parseInt(dateParts[0]);
            int month = Integer.parseInt(dateParts[1]);
            int day = Integer.parseInt(dateParts[2]);
            LocalDate.of(year, month, day);
        } catch (Exception e) {
            return false;
        }

        return true;
    }

    public static boolean formatCheckTimeString(String str) {
        // 19:00~22:00
        String[] timesPart = str.split("~");
        if (timesPart.length != 2)
            return false;

        LocalTime beginTime = null;
        String[] hourMin1 = timesPart[0].split(":");
        if (!hourMin1[1].equals("00"))
            return false;

        try {
            int hour = Integer.parseInt(hourMin1[0]);
            int min = Integer.parseInt(hourMin1[1]);
            beginTime = LocalTime.of(hour, min);
        } catch (Exception e) {
            return false;
        }

        LocalTime endTime = null;
        String[] hourMin2 = timesPart[1].split(":");
        if (!hourMin2[1].equals("00"))
            return false;

        try {
            int hour = Integer.parseInt(hourMin2[0]);
            int min = Integer.parseInt(hourMin2[1]);
            endTime = LocalTime.of(hour, min);
        } catch (Exception e) {
            return false;
        }

        if (beginTime.getHour() >= endTime.getHour())
            return false;

        return true;
    }

    public static boolean formatCheckInputString(String str) {
        // U002 2017-08-01 19:00~22:00 A C

        // String Words Check
        String[] inputParts = str.split(" ");
        if (inputParts.length < 4 || inputParts.length > 5)
            return false;

        // String Date Check
        String dateStr = inputParts[1];
        if (!formatCheckDateString(dateStr))
            return false;

        // String Times Check
        String timesStr = inputParts[2];
        if (!formatCheckTimeString(timesStr))
            return false;

        // String Cancel Check
        if (inputParts.length == 5) {
            String cancelFlag = inputParts[4];
            if (!cancelFlag.equals("C"))
                return false;
        }

        return true;
    }
}
